﻿using System;
using System.Collections.Generic;

namespace Tomato.Allure.Samples
{
	class SolutionFileEntry
	{
		public class Comparer : IComparer<SolutionFileEntry>
		{
			public int Compare( SolutionFileEntry item1, SolutionFileEntry item2 )
			{
				if( item1.m_lastOpenTime == item2.m_lastOpenTime )
				{
					return item1.ProjectItem.Name.CompareTo( item2.ProjectItem.Name );
				}
				else
				{
					return item1.m_lastOpenTime.CompareTo( item2.m_lastOpenTime );
				}
			}
		}

		private IProjectItem m_projectItem = null;
		private DateTime m_lastOpenTime;

		public IProjectItem ProjectItem
		{
			get { return m_projectItem; }
		}

		public SolutionFileEntry( IProjectItem projectItem )
		{
			m_projectItem = projectItem;
			m_lastOpenTime = DateTime.MinValue;
		}

		public void Open()
		{
			try
			{
				m_projectItem.Open().Activate();
				m_lastOpenTime = DateTime.Now;
			}
			catch( Exception ) { }
		}

		public override string ToString()
		{
			if( m_projectItem != null )
			{
				return m_projectItem.Name;
			}
			else
			{
				return "(invalid project item)";
			}
		}
	}
}
